package com.videoaggre.zcl.ui.fragment.enterdesk

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.videoaggre.zcl.R
import com.videoaggre.zcl.bean.EnterdeskClassify
import com.videoaggre.zcl.common.ENTERDESK_CLASSIFY
import com.videoaggre.zcl.common.dp
import com.videoaggre.zcl.common.startKtxActivity
import com.videoaggre.zcl.common.toColor
import com.videoaggre.zcl.databinding.EnterdeskItemBrandBinding
import com.videoaggre.zcl.ui.activity.wallpaper.enterdesk.EnterdeskBrandImageActivity
import com.videoaggre.zcl.ui.adapter.BaseRecyclerAdapter
import com.videoaggre.zcl.ui.adapter.BaseViewHolder
import com.videoaggre.zcl.ui.fragment.BaseFragment
import kotlinx.android.synthetic.main.view_refresh.*

class EnterdeskBrandFragtment : BaseFragment(R.layout.view_refresh) {
    protected val mEnterdeskBrandAdapter = EnterdeskBrandAdapter()
    override fun initView(rootView: View?, savedInstanceState: Bundle?) {
        refreshLayout.apply {
            setBackgroundColor(R.color.white.toColor())
            setEnableRefresh(false)
            setEnableLoadMore(false)
        }
        recyclerView.adapter = mEnterdeskBrandAdapter
        recyclerView.layoutManager = GridLayoutManager(context, 2)
        recyclerView.setPadding(3.dp, (-3).dp, 3.dp, 3.dp)
    }

    override fun initData(rootView: View?, savedInstanceState: Bundle?) {
        mEnterdeskBrandAdapter.datas = mutableListOf<EnterdeskClassify>().apply {
            add(EnterdeskClassify("", "苹果", "apple", R.mipmap.phone_logo_apple))
            add(EnterdeskClassify("", "oppo", "oppo", R.mipmap.phone_logo_oppo))
            add(EnterdeskClassify("", "vivo", "vivo", R.mipmap.phone_logo_vivo))
            add(EnterdeskClassify("", "三星", "samsung", R.mipmap.phone_logo_sx))
            add(EnterdeskClassify("", "华为", "huawei", R.mipmap.phone_logo_huawei))
            add(EnterdeskClassify("", "小米", "xiaomi", R.mipmap.phone_logo_xiaomi))
            add(EnterdeskClassify("", "魅族", "meizu", R.mipmap.phone_logo_meizu))
            add(EnterdeskClassify("", "锤子", "smartisan", R.mipmap.phone_logo_chuizi))
            add(EnterdeskClassify("", "一加", "oneplus", R.mipmap.phone_logo_one_puls))
            add(EnterdeskClassify("", "美图", "meitu", R.mipmap.phone_logo_meitu))
            add(EnterdeskClassify("", "乐视", "le", R.mipmap.phone_logo_leshi))
            add(EnterdeskClassify("", "诺基亚", "nokia", R.mipmap.phone_logo_nokia))
            add(EnterdeskClassify("", "360", "360", R.mipmap.phone_logo_360))
            add(EnterdeskClassify("", "中兴", "zte", R.mipmap.phone_logo_zte))
            add(EnterdeskClassify("", "HCT", "htc", R.mipmap.phone_logo_htc))
            add(EnterdeskClassify("", "联想", "lenovo", R.mipmap.phone_logo_lianxiang))
            add(EnterdeskClassify("", "索尼", "sony", R.mipmap.phone_logo_sony))
            add(EnterdeskClassify("", "酷派", "coolpad", R.mipmap.phone_logo_kupai))
            add(EnterdeskClassify("", "努比亚", "nubia", R.mipmap.phone_logo_nubiya))
        }
    }

    class EnterdeskBrandAdapter : BaseRecyclerAdapter<BaseViewHolder<EnterdeskItemBrandBinding>, EnterdeskClassify>() {
        override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = BaseViewHolder(EnterdeskItemBrandBinding.inflate(getLayoutInflate(parent.context), parent, false))
        override fun onBindViewHolder(holder: BaseViewHolder<EnterdeskItemBrandBinding>, bean: EnterdeskClassify, position: Int) {
            holder.mViewBinding.apply {
                bean.apply {
                    tvBrandName.text = name
                    ivImage.setImageResource(resId)
                    setViewClick(position, root)
                }
            }
        }

        override fun subOnClickAdapter(v: View, position: Int) {
            v.context.startKtxActivity<EnterdeskBrandImageActivity>(value = ENTERDESK_CLASSIFY to getItem(position))
        }
    }
}